from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import gettext_lazy as _

class UserRole(models.TextChoices):
    """用户角色选项"""
    NORMAL = 'normal', _('普通用户')
    SUPER_ADMIN = 'super_admin', _('超级管理员')

class User(AbstractUser):
    """自定义用户模型"""
    phone = models.CharField(
        _('手机号'), 
        max_length=11, 
        blank=True, 
        null=True, 
        unique=True, 
        help_text=_('请输入11位手机号码')
    )
    
    role = models.CharField(
        _('角色'),
        max_length=20,
        choices=UserRole.choices,
        default=UserRole.NORMAL,
        help_text=_('用户角色，普通用户或超级管理员')
    )
    
    # 保留默认字段：username, password, email等
    
    class Meta:
        verbose_name = _('用户')
        verbose_name_plural = _('用户')
    
    def __str__(self):
        return self.username
    
    def is_super_admin(self):
        """判断用户是否为超级管理员"""
        return self.role == UserRole.SUPER_ADMIN
    
    def is_normal_user(self):
        """判断用户是否为普通用户"""
        return self.role == UserRole.NORMAL
